package com.hoshiicloud.market.feign.hystrix;

import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.market.feign.GoodsService;
import com.hoshiicloud.saleorder.param.customer.ExtSkuQueryParam;
import com.hoshiicloud.user.dto.customer.SkuDTO;
import com.hoshiicloud.user.entity.customer.ExtSku;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author Mr.wu
 * @title: HystrixGoodsFeignFallback
 * @projectName hoshiicloud-customer
 * @description:HystrixGoodsFeignFallback
 * @since 2019-05-21
 */
@Component
@Slf4j
public class HystrixGoodsFeignFallback implements FallbackFactory<GoodsService> {

    @Override
    public GoodsService create(Throwable throwable) {
        log.error("fallback; reason was:"+throwable.toString());
        return new GoodsService() {
            @Override
            public Response<SkuDTO> getExtSku(Long id) {
                return Response.failed("商品服务异常");
            }

            @Override
            public Response<ExtSku> getGoodsDetailById(String skuId) {
                return Response.failed("商品服务异常");
            }

            @Override
            public Response<List<ExtSku>> getGoodsDetailByIds(List<Long> param) {
                return Response.failed("商品服务异常");
            }

            @Override
            public Response getGoodsPage(ExtSkuQueryParam param) {
                return Response.failed("商品服务异常");
            }

            @Override
            public Response<Map<Long, SkuDTO>> querySKuStockByIds(List<Long> ids){return Response.failed("商品服务异常");}
        };
    }
}
